//
//  HCWelcomeViewController.swift
//  Hweibome
//
//  Created by 何川 on 15/12/9.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage

class HCWelcomeViewController: UIViewController {
    
     //MARK: - lazy
    private lazy var bgImageView:UIImageView =
    {
        let image = UIImage(named: "ad_background")
        return UIImageView(image: image)
    }()
    
    private lazy var headImageView: UIImageView =
    {
        let imageView = UIImageView(image: UIImage(named: "avatar_default_big"))
        imageView.sd_setImageWithURL(NSURL(string: HCUserAccountViewModel.sharedAccount.userAccount!.avatar_large!)!,placeholderImage: UIImage(named: "avatar_default_big"))
        imageView.cornerRadius = 45
        return imageView
    }()
    
    private lazy var messageLabel:UILabel =
    {
        let label = UILabel()
        label.font = UIFont.systemFontOfSize(18)
        label.textColor = UIColor.darkGrayColor()
        label.text = "欢迎回来"
        return label
    }()
    
     //MARK: - 加载试图
    override func loadView() {
        view = bgImageView
        
        setupUI()
    }
    
    private func setupUI()
    {
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        //约束
        headImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(view.snp_top).offset(200)
            make.size.equalTo(CGSize(width: 90, height: 90))
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(headImageView)
            make.top.equalTo(headImageView.snp_bottom).offset(20)
        }
        
    }
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
        messageLabel.alpha = 0
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.4, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.6, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(HCSwitchRootVCNotifation, object: nil)
                
                })
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

}


















